package com.facebook.imagepipeline.animated.impl;

import android.graphics.Bitmap;
import android.graphics.Canvas;
import android.graphics.Paint;
import android.graphics.Paint.Style;
import android.graphics.PorterDuff.Mode;
import android.graphics.PorterDuffXfermode;
import com.facebook.common.references.CloseableReference;
import com.facebook.imagepipeline.animated.base.AnimatedDrawableBackend;
import com.facebook.imagepipeline.animated.base.AnimatedDrawableFrameInfo;
import com.facebook.imagepipeline.animated.base.AnimatedDrawableFrameInfo.BlendOperation;
import com.facebook.imagepipeline.animated.base.AnimatedDrawableFrameInfo.DisposalMethod;

public class AnimatedImageCompositor
{
  private final AnimatedDrawableBackend mAnimatedDrawableBackend;
  private final Callback mCallback;
  private final Paint mTransparentFillPaint;

  public AnimatedImageCompositor(AnimatedDrawableBackend paramAnimatedDrawableBackend, Callback paramCallback)
  {
    this.mAnimatedDrawableBackend = paramAnimatedDrawableBackend;
    this.mCallback = paramCallback;
    this.mTransparentFillPaint = new Paint();
    this.mTransparentFillPaint.setColor(0);
    this.mTransparentFillPaint.setStyle(Paint.Style.FILL);
    this.mTransparentFillPaint.setXfermode(new PorterDuffXfermode(PorterDuff.Mode.SRC));
  }

  private void disposeToBackground(Canvas paramCanvas, AnimatedDrawableFrameInfo paramAnimatedDrawableFrameInfo)
  {
    paramCanvas.drawRect(paramAnimatedDrawableFrameInfo.xOffset, paramAnimatedDrawableFrameInfo.yOffset, paramAnimatedDrawableFrameInfo.xOffset + paramAnimatedDrawableFrameInfo.width, paramAnimatedDrawableFrameInfo.yOffset + paramAnimatedDrawableFrameInfo.height, this.mTransparentFillPaint);
  }

  private FrameNeededResult isFrameNeededForRendering(int paramInt)
  {
    AnimatedDrawableFrameInfo localAnimatedDrawableFrameInfo = this.mAnimatedDrawableBackend.getFrameInfo(paramInt);
    AnimatedDrawableFrameInfo.DisposalMethod localDisposalMethod = localAnimatedDrawableFrameInfo.disposalMethod;
    if (localDisposalMethod == AnimatedDrawableFrameInfo.DisposalMethod.DISPOSE_DO_NOT)
      return FrameNeededResult.REQUIRED;
    if (localDisposalMethod == AnimatedDrawableFrameInfo.DisposalMethod.DISPOSE_TO_BACKGROUND)
    {
      if (isFullFrame(localAnimatedDrawableFrameInfo))
        return FrameNeededResult.NOT_REQUIRED;
      return FrameNeededResult.REQUIRED;
    }
    if (localDisposalMethod == AnimatedDrawableFrameInfo.DisposalMethod.DISPOSE_TO_PREVIOUS)
      return FrameNeededResult.SKIP;
    return FrameNeededResult.ABORT;
  }

  private boolean isFullFrame(AnimatedDrawableFrameInfo paramAnimatedDrawableFrameInfo)
  {
    return (paramAnimatedDrawableFrameInfo.xOffset == 0) && (paramAnimatedDrawableFrameInfo.yOffset == 0) && (paramAnimatedDrawableFrameInfo.width == this.mAnimatedDrawableBackend.getRenderedWidth()) && (paramAnimatedDrawableFrameInfo.height == this.mAnimatedDrawableBackend.getRenderedHeight());
  }

  private boolean isKeyFrame(int paramInt)
  {
    if (paramInt == 0);
    AnimatedDrawableFrameInfo localAnimatedDrawableFrameInfo1;
    AnimatedDrawableFrameInfo localAnimatedDrawableFrameInfo2;
    do
    {
      return true;
      localAnimatedDrawableFrameInfo1 = this.mAnimatedDrawableBackend.getFrameInfo(paramInt);
      localAnimatedDrawableFrameInfo2 = this.mAnimatedDrawableBackend.getFrameInfo(paramInt - 1);
    }
    while (((localAnimatedDrawableFrameInfo1.blendOperation == AnimatedDrawableFrameInfo.BlendOperation.NO_BLEND) && (isFullFrame(localAnimatedDrawableFrameInfo1))) || ((localAnimatedDrawableFrameInfo2.disposalMethod == AnimatedDrawableFrameInfo.DisposalMethod.DISPOSE_TO_BACKGROUND) && (isFullFrame(localAnimatedDrawableFrameInfo2))));
    return false;
  }

  private int prepareCanvasWithClosestCachedFrame(int paramInt, Canvas paramCanvas)
  {
    int i = paramInt;
    if (i >= 0)
    {
      FrameNeededResult localFrameNeededResult = isFrameNeededForRendering(i);
      switch (1.$SwitchMap$com$facebook$imagepipeline$animated$impl$AnimatedImageCompositor$FrameNeededResult[localFrameNeededResult.ordinal()])
      {
      default:
      case 1:
      case 3:
        do
        {
          i--;
          break;
          AnimatedDrawableFrameInfo localAnimatedDrawableFrameInfo = this.mAnimatedDrawableBackend.getFrameInfo(i);
          CloseableReference localCloseableReference = this.mCallback.getCachedBitmap(i);
          if (localCloseableReference != null)
            try
            {
              paramCanvas.drawBitmap((Bitmap)localCloseableReference.get(), 0.0F, 0.0F, null);
              if (localAnimatedDrawableFrameInfo.disposalMethod == AnimatedDrawableFrameInfo.DisposalMethod.DISPOSE_TO_BACKGROUND)
                disposeToBackground(paramCanvas, localAnimatedDrawableFrameInfo);
              i++;
              return i;
            }
            finally
            {
              localCloseableReference.close();
            }
        }
        while (!isKeyFrame(i));
        return i;
      case 2:
      }
      return i + 1;
    }
    return 0;
  }

  public void renderFrame(int paramInt, Bitmap paramBitmap)
  {
    Canvas localCanvas = new Canvas(paramBitmap);
    localCanvas.drawColor(0, PorterDuff.Mode.SRC);
    int i;
    int j;
    label39: AnimatedDrawableFrameInfo localAnimatedDrawableFrameInfo2;
    AnimatedDrawableFrameInfo.DisposalMethod localDisposalMethod;
    if (!isKeyFrame(paramInt))
    {
      i = prepareCanvasWithClosestCachedFrame(paramInt - 1, localCanvas);
      j = i;
      if (j >= paramInt)
        break label145;
      localAnimatedDrawableFrameInfo2 = this.mAnimatedDrawableBackend.getFrameInfo(j);
      localDisposalMethod = localAnimatedDrawableFrameInfo2.disposalMethod;
      if (localDisposalMethod != AnimatedDrawableFrameInfo.DisposalMethod.DISPOSE_TO_PREVIOUS)
        break label85;
    }
    while (true)
    {
      j++;
      break label39;
      i = paramInt;
      break;
      label85: if (localAnimatedDrawableFrameInfo2.blendOperation == AnimatedDrawableFrameInfo.BlendOperation.NO_BLEND)
        disposeToBackground(localCanvas, localAnimatedDrawableFrameInfo2);
      this.mAnimatedDrawableBackend.renderFrame(j, localCanvas);
      this.mCallback.onIntermediateResult(j, paramBitmap);
      if (localDisposalMethod == AnimatedDrawableFrameInfo.DisposalMethod.DISPOSE_TO_BACKGROUND)
        disposeToBackground(localCanvas, localAnimatedDrawableFrameInfo2);
    }
    label145: AnimatedDrawableFrameInfo localAnimatedDrawableFrameInfo1 = this.mAnimatedDrawableBackend.getFrameInfo(paramInt);
    if (localAnimatedDrawableFrameInfo1.blendOperation == AnimatedDrawableFrameInfo.BlendOperation.NO_BLEND)
      disposeToBackground(localCanvas, localAnimatedDrawableFrameInfo1);
    this.mAnimatedDrawableBackend.renderFrame(paramInt, localCanvas);
  }

  public static abstract interface Callback
  {
    public abstract CloseableReference<Bitmap> getCachedBitmap(int paramInt);

    public abstract void onIntermediateResult(int paramInt, Bitmap paramBitmap);
  }

  private static enum FrameNeededResult
  {
    static
    {
      NOT_REQUIRED = new FrameNeededResult("NOT_REQUIRED", 1);
      SKIP = new FrameNeededResult("SKIP", 2);
      ABORT = new FrameNeededResult("ABORT", 3);
      FrameNeededResult[] arrayOfFrameNeededResult = new FrameNeededResult[4];
      arrayOfFrameNeededResult[0] = REQUIRED;
      arrayOfFrameNeededResult[1] = NOT_REQUIRED;
      arrayOfFrameNeededResult[2] = SKIP;
      arrayOfFrameNeededResult[3] = ABORT;
    }
  }
}

/* Location:           C:\Users\user\Desktop\dd28_pcdd720\classes_dex2jar.jar
 * Qualified Name:     com.facebook.imagepipeline.animated.impl.AnimatedImageCompositor
 * JD-Core Version:    0.6.2
 */